#ifndef TYPES_H
#define TYPES_H

#include <stdint.h>
#include <cassert>
#include "operations.pb.h"

enum Type {
	INT = ScanOperation::INT,
	DOUBLE = ScanOperation::DOUBLE,
	BOOL = ScanOperation::BOOL
};

namespace {

template <typename T>
Type type();

template <>
Type type<int32_t>() { return INT; }

template <>
Type type<double>() { return DOUBLE; }

template <>
Type type<bool>() { return BOOL; }

int typeSizeOf(Type t) {
	switch (t) {
		case INT:
			return sizeof(int32_t);

		case DOUBLE:
			return sizeof(double);

		case BOOL:
			return sizeof(bool);

		default:
			assert(false);
	}

	return -1;
}

void* allocArray(Type t, int size) {
	switch (t) {
		case INT:
			return reinterpret_cast<void*>(new int32_t[size]);

		case DOUBLE:
			return reinterpret_cast<void*>(new double[size]);

		case BOOL:
			return reinterpret_cast<void*>(new bool[size]);

		default:
			assert(false);
	}

	return 0;
}

}

#endif
